package cn.kgc.javaweb.utils;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/5/16
 * @Description:
 */
public class JSONResult {

    public static  void writeJson(Object data, HttpServletResponse resp){
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter writer = null;
        try {
            writer = resp.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String result = JSON.toJSONString(data);
        writer.write(result);
        writer.close();
    }

}
